package com.zl.zlbaseproject.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SpUtils {
	public static final String NAME="配置文件";
	public static SharedPreferences sp;
	private static SharedPreferences getSP(Context context){
		if(sp==null){
			sp=context.getSharedPreferences(NAME, 0);
		}
		return sp;
	}
	
	public static boolean getBoolean(Context context,String key,Boolean defValue){
		sp=getSP(context);
		return sp.getBoolean(key, defValue);
	}
	
	public static boolean getBoolean(Context context,String key){
		return getBoolean(context, key,false);
	}
	
	public static void setBoolean(Context context ,String key ,Boolean value){
		sp=getSP(context);
		Editor editor = sp.edit();
		editor.putBoolean(key, value);
		editor.apply();
	}
	
	public static String getString(Context context,String key,String defValue){
		sp=getSP(context);
		return sp.getString(key, defValue);
	}
	
	public static String getString(Context context,String key){
		return getString(context, key,null);
	}
	
	public static void setString(Context context ,String key ,String value){
		sp=getSP(context);
		Editor editor = sp.edit();
		editor.putString(key, value);
		editor.apply();
	}

	public static int getInt(Context context,String key,int defValue){
		sp=getSP(context);
		return sp.getInt(key, defValue);
	}
	
	public static int getInt(Context context,String key){
		return getInt(context, key,-1);
	}
	
	public static void setInt(Context context ,String key ,int value){
		sp=getSP(context);
		Editor editor = sp.edit();
		editor.putInt(key, value);
		editor.apply();
	}
}
